package net.sytes.hamir.importadorchess;

import java.util.Collection;

import net.sytes.hamir.importadorchess.pgnreader.AbstractReader;
import net.sytes.hamir.importadorchess.pgnreader.MailReader;

public class GamesImporter {
	
	

	public static void main(String[] args) {
		AbstractReader reader = new MailReader("atualizadorchess", "estatisticaschess", "Inbox");

		Collection<Game> games = reader.read();
		DBGameSaver saver = new DBGameSaver();
		try{
			saver.open();
			for(Game g:games){
				saver.saveGame(g);
			}
			saver.commitChanges();
		} catch(Exception e){
			saver.rollbackChanges();
			e.printStackTrace();
		} finally {
			saver.close();
		}
	}

}
